<template>
  <BasicModal v-bind="$attrs" @register="register" showFooter :title="getTitle" width="70%" @ok="handleSubmit">

    <BasicForm @register="registerForm" />


  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, h, toRaw, reactive } from 'vue';
import { BasicForm, useForm } from '@/components/Form';


import {
  formSchema,
} from './role.data';

import { BasicModal, useModalInner } from '@/components/Modal';
import { Form, FormItem, Input, InputNumber, DatePicker, Select, Switch } from 'ant-design-vue';


import { productSave } from '@/api/heng/dkn';


import { useMessage } from "@/hooks/web/useMessage";
import util from '@/utils/util';

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const { createMessage } = useMessage();


const id = ref("")

const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
  labelWidth: 100,
  schemas: formSchema,
  showActionButtonGroup: false,
  baseColProps: { lg: 12, md: 24 },
});


const dataList = ref({});

const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //打开弹层后的回调
  // resetFields();
  setModalProps({ confirmLoading: false });
  dataList.value = data.record;
  setFieldsValue(data.record);

});

const getTitle = computed(() => ('产品映射编辑'));


//async function handleSubmit()

async function handleSubmit() {
  try {

    const values = await validate();
    productSave(values).then(res => {
      sunccFn(res)
    });


  } catch (e) {
    console.log(e)
  } finally {
    setModalProps({ confirmLoading: false });

  }
}

function sunccFn(result) {
  if (result && result.code == 200) {
    createMessage.success(result.message);
  } else {
    createMessage.error(result.message);
  }
  closeModal()
  emit('success');
}

function cancelFn() {
  //  tableRef.value.clearValidate();
}



</script>
<style lang="less">
.item-row {
  margin: 0 auto;

  //padding-left: 5%;
  .ant-form-item-label {
    flex: 0 0 28.5%;
    max-width: 28.5%;
  }
}

.lqfp-8 {
  //padding-left: 9% !important;

}
</style>
